/* 
 * File:   Lesson4.cpp
 * Author: jose
 * 
 * Created on March 29, 2012, 1:45 PM
 */

#include "Lesson4.h"
#include "SdlUtils.h"
#include <iostream>

using namespace std;

Lesson4::Lesson4() {
}

Lesson4::Lesson4(const Lesson4& orig) {
}

Lesson4::~Lesson4() {
}

bool Lesson4::init(){
    
    if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
    {
        return false;
    }
    
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
    
    if( screen == NULL)
    {
        return false;
    }
    
    SDL_WM_SetCaption("Event test", NULL);
    
    return true;
}
int Lesson4::Run(){
    
    if( init() == false)
    {
        cout << "Could not init" << endl;
        return 1;
    }
    
    message = SdlUtils::loadImage("event.png");
    
    if(message == NULL)
    {
        cout << "Could not load the image" << endl;
        return 1;
    }
    
    SdlUtils::applySurface(0, 0, message, screen );
    
    if(SDL_Flip(screen) == -1)
    {
        return 1;
    }
    
    bool quit = false;
    SDL_Event event;
    
    while(!quit)
    {
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                quit = true;
            }
        }
    }
    
    SDL_FreeSurface( message );

    SDL_Quit();
    
    return 0;
}